package com.prd.controller;


import com.prd.dto.AttendanceOtDTO;
import com.prd.service.AttendanceOtService;
import com.prd.util.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * <p>
 * 加班管理表数据 前端控制器
 * </p>
 *
 * @author lizhaoyi
 * @since 2023-10-19
 */
@Api(tags={"加班管理"})
@RestController
@RequestMapping("/api/ot")
public class AttendanceOtController {

    @Autowired
    private AttendanceOtService attendanceOtService;

    @ApiOperation("申请加班并启动工作流")
    @PostMapping("/askForOt")
    public JsonData askForOt(@RequestBody AttendanceOtDTO attendanceOtDTO){

        JsonData jsonData = attendanceOtService.askForOt(attendanceOtDTO);

        return jsonData;
    }

    @ApiOperation("分页查询加班申请记录")
    @GetMapping("page")
    public JsonData pageOutsideList(
            @ApiParam(value = "当前页")  @RequestParam(value = "page", defaultValue = "1") int page,
            @ApiParam(value = "每页显示多少条") @RequestParam(value = "size", defaultValue = "10") int size,
            @ApiParam(value = "用户id") @RequestParam(value = "userId") String userId
    ){

        Map<String,Object> pageResult = attendanceOtService.page(page,size,userId);

        return JsonData.buildSuccess(pageResult);

    }

    @ApiOperation("查看申请加班详情")
    @GetMapping("detail")
    public JsonData detail(
            @ApiParam(value = "申请加班记录id") @RequestParam(value = "id") int id,
            @ApiParam(value = "用户id") @RequestParam(value = "userId") String userId
    ){

        JsonData jsonData = attendanceOtService.getDetail(id,userId);

        return jsonData;

    }

    @ApiOperation("查看工作流程图")
    @GetMapping("showProcessPic")
    public void showProcessPic(HttpServletResponse resp, String processId) throws IOException {

        attendanceOtService.showProcessPic(resp,processId);

    }

    @ApiOperation("取消加班")
    @PostMapping("/cancelOt")
    public JsonData cancelOt(@RequestBody AttendanceOtDTO attendanceOtDTO){

        JsonData jsonData = attendanceOtService.cancelOt(attendanceOtDTO);

        return jsonData;
    }

}

